package com.humanresource.service.impl.clerksalary;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.humanresource.constant.Constant;
import com.humanresource.dao.mapper.clerksalary.ClerkrewardpunishstandardMapper;
import com.humanresource.dao.mapper.clerksalary.PossalarystandardMapper;
import com.humanresource.dao.mapper.clerksalary.RewardpunishmentstandardMapper;
import com.humanresource.dao.mapper.clerksalary.SalarydistributionMapper;
import com.humanresource.dao.mapper.clerksalary.SalarydistributiondetailMapper;
import com.humanresource.dao.mapper.clerksalary.SalarystandardMapper;
import com.humanresource.domain.po.clerkrecord.Clerkbaseinfo;
import com.humanresource.domain.po.clerkrecord.Clerkinstpos;
import com.humanresource.domain.po.clerkrecord.Clerkrecords;
import com.humanresource.domain.po.clerksalary.Clerkrewardpunishstandard;
import com.humanresource.domain.po.clerksalary.ClerkrewardpunishstandardExample;
import com.humanresource.domain.po.clerksalary.Rewardpunishmentstandard;
import com.humanresource.domain.po.clerksalary.Salarydistribution;
import com.humanresource.domain.po.clerksalary.SalarydistributionExample;
import com.humanresource.domain.po.clerksalary.Salarydistributiondetail;
import com.humanresource.domain.po.clerksalary.SalarydistributiondetailExample;
import com.humanresource.domain.po.clerksalary.Salarystandard;
import com.humanresource.domain.po.clerksalary.SalarystandardExample;
import com.humanresource.domain.vo.clerksalary.SalaryDistributionDetailVO;
import com.humanresource.service.clerkrecord.ClerkBaseInfoService;
import com.humanresource.service.clerkrecord.ClerkRecordService;
import com.humanresource.service.clerkrecord.PosService;
import com.humanresource.service.clerksalary.SalarystandardService;
import com.humanresource.utils.DereplicationListUtil;
import com.humanresource.utils.RandomUtils;
import com.humanresource.utils.ValidateUtil;

@Service
public class SalarystandardServiceImpl implements SalarystandardService {

	@Autowired
	private SalarystandardMapper salarystandardMapper;

	@Autowired
	private ClerkBaseInfoService clerkBaseInfoService;

	@Autowired
	private PosService posService;

	@Autowired
	private PossalarystandardMapper possalarystandardMapper;

	@Autowired
	private ClerkRecordService clerkRecordService;

	@Autowired
	private ClerkrewardpunishstandardMapper clerkrewardpunishstandardMapper;

	@Autowired
	private RewardpunishmentstandardMapper rewardpunishmentstandardMapper;

	@Autowired
	private SalarydistributionMapper salarydistributionMapper;

	@Autowired
	private SalarydistributiondetailMapper salarydistributiondetailMapper;

	@Override
	public void insert(Salarystandard salarystandard) {
		this.salarystandardMapper.insertSelective(salarystandard);
	}

	@Override
	public Salarystandard findById(String salarystandardId) {
		return this.salarystandardMapper.selectByPrimaryKey(salarystandardId);
	}

	@Override
	public Salarystandard findByName(String salarystandardName) {
		SalarystandardExample salarystandardExample = new SalarystandardExample();
		SalarystandardExample.Criteria criteria = salarystandardExample
				.createCriteria();
		criteria.andSalarystandardnameEqualTo(salarystandardName);
		return this.salarystandardMapper.selectByExampleWithBLOBs(
				salarystandardExample).get(0);
	}

	@Override
	public List<Salarystandard> findbyAuditstate(String Auditstate) {
		SalarystandardExample salarystandardExample = new SalarystandardExample();
		SalarystandardExample.Criteria criteria = salarystandardExample
				.createCriteria();
		criteria.andAuditstateEqualTo(Auditstate);
		return this.salarystandardMapper
				.selectByExampleWithBLOBs(salarystandardExample);
	}

	@Override
	public void update(Salarystandard salarystandard) {
		this.salarystandardMapper.updateByPrimaryKeySelective(salarystandard);
	}

	@Override
	public List<Salarystandard> keywordquery(String keyword, String starttime,
			String endtime) {
		/**
		 * 关键字查询条件在薪酬标准名称、制定人、变更人和复核人字段进行匹配
		 */
		// 封装所有符合条件的结果集
		List<Salarystandard> salarystandards = new ArrayList<Salarystandard>();

		/**
		 *  薪酬标准名称模糊查询
		 */
		SalarystandardExample slarystandardnameexample = new SalarystandardExample();
		SalarystandardExample.Criteria slarystandardnameCriteria = slarystandardnameexample
				.createCriteria();
		slarystandardnameCriteria
				.andSalarystandardnameLike("%" + keyword + "%");

		/**
		 * 根据关键字查找所有的职工信息
		 */
		List<Clerkbaseinfo> clerkbaseinfos = this.clerkBaseInfoService
				.clerknameLike(keyword);

		/**
		 * 创造查询条件
		 */
		SalarystandardExample setternameExample = new SalarystandardExample();
		SalarystandardExample.Criteria setternameCriteria = setternameExample
				.createCriteria();

		SalarystandardExample checkernameExample = new SalarystandardExample();
		SalarystandardExample.Criteria checkernameCriteria = checkernameExample
				.createCriteria();

		SalarystandardExample changepersonnameExample = new SalarystandardExample();
		SalarystandardExample.Criteria changepersonnameCriteria = changepersonnameExample
				.createCriteria();
		/**
		 * 如果存在符合条件的职工，则进行制定人，复核人，变更人的模糊查询
		 */
		if (clerkbaseinfos.size() != 0) {
			/**
			 * 封装所有的职工的职工编号
			 */
			List<Integer> clerkIds = new ArrayList<Integer>();
			for (Clerkbaseinfo clerkbaseinfo : clerkbaseinfos) {
				clerkIds.add(clerkbaseinfo.getClerkid());
			}

			/**
			 * 制定人模糊查询
			 */
			setternameCriteria.andSettersidIn(clerkIds);
			/**
			 * 复核人模糊查询
			 */
			checkernameCriteria.andCheckeridIn(clerkIds);
			/**
			 * 变更人模糊查询
			 */
			changepersonnameCriteria.andChangepersonidIn(clerkIds);

		}

		if (!ValidateUtil.isNull(starttime) && !ValidateUtil.isNull(endtime)) {
			slarystandardnameCriteria.andBooktimeBetween(starttime, endtime);

			if (clerkbaseinfos.size() != 0) {
				setternameCriteria.andBooktimeBetween(starttime, endtime);
				checkernameCriteria.andBooktimeBetween(starttime, endtime);
				changepersonnameCriteria.andBooktimeBetween(starttime, endtime);
			}
		}

		/**
		 * 跟句薪酬标准名称模糊查询到的结果集
		 */
		List<Salarystandard> salarystandardnameList = this.salarystandardMapper
				.selectByExampleWithBLOBs(slarystandardnameexample);

		if (clerkbaseinfos.size() != 0) {
			/**
			 * 根据制定人模糊查询得到的结果集
			 */
			List<Salarystandard> setternameList = this.salarystandardMapper
					.selectByExampleWithBLOBs(setternameExample);
			/**
			 * 根据复核人模糊查询得到的结果集
			 */
			List<Salarystandard> checkernameList = this.salarystandardMapper
					.selectByExampleWithBLOBs(checkernameExample);
			/**
			 * 根据变更人模糊查询得到的结果集
			 */
			List<Salarystandard> changepersonnameList = this.salarystandardMapper
					.selectByExampleWithBLOBs(changepersonnameExample);

			if (setternameList.size() != 0) {
				salarystandards.addAll(setternameList);
			}

			if (checkernameList.size() != 0) {
				salarystandards = DereplicationListUtil.dereplication(
						checkernameList, salarystandards);
			}

			if (changepersonnameList.size() != 0) {
				salarystandards = DereplicationListUtil.dereplication(
						changepersonnameList, salarystandards);
			}
		}

		if (salarystandardnameList.size() != 0) {
			salarystandards = DereplicationListUtil.dereplication(
					salarystandardnameList, salarystandards);
		}

		return salarystandards;
	}

	@Override
	public List<Salarystandard> findlikequery(String salarystandardid,
			String keyword, String starttime, String endtime) {
		SalarystandardExample salarystandardExample = new SalarystandardExample();
		SalarystandardExample.Criteria criteria = salarystandardExample
				.createCriteria();

		if (!ValidateUtil.isNull(keyword)) {// 关键字模糊查询
			return keywordquery(keyword, starttime, endtime);
		} else if (!ValidateUtil.isNull(salarystandardid)) {// 薪酬标准编号查询
			criteria.andSalarystandardidEqualTo(salarystandardid);
			if (!ValidateUtil.isNull(starttime)
					&& !ValidateUtil.isNull(endtime)) {
				criteria.andBooktimeBetween(starttime, endtime);
			}
		} else if (!ValidateUtil.isNull(starttime)
				&& !ValidateUtil.isNull(endtime)) {
			criteria.andBooktimeBetween(starttime, endtime);
		} else {// 没有任何查询条件时，全部查询
			criteria.andSalarystandardidIsNotNull();
		}
		return this.salarystandardMapper
				.selectByExampleWithBLOBs(salarystandardExample);
	}

	@Override
	public Float getBasicSalaryMoneyBySalarystandardId(String salarystandardId) {
		float basicSalary = 0;
		Salarystandard salarystandard = this.findById(salarystandardId);
		if (salarystandard.getBasicsalary() != null) {
			basicSalary += salarystandard.getBasicsalary();
		}
		if (salarystandard.getTrafficallowance() != null) {
			basicSalary += salarystandard.getTrafficallowance();
		}
		if (salarystandard.getLunchallowance() != null) {
			basicSalary += salarystandard.getLunchallowance();
		}
		if (salarystandard.getCommallowance() != null) {
			basicSalary += salarystandard.getCommallowance();
		}
		if (salarystandard.getEndowmentins() != null) {
			basicSalary -= salarystandard.getEndowmentins();
		}
		if (salarystandard.getMedicalins() != null) {
			basicSalary -= salarystandard.getMedicalins();
		}
		if (salarystandard.getUneloymentins() != null) {
			basicSalary -= salarystandard.getUneloymentins();
		}
		if (salarystandard.getHousingfund() != null) {
			basicSalary -= salarystandard.getHousingfund();
		}
		return basicSalary;
	}

	@Override
	@Deprecated
	public Float getBasicSalaryMoneySum(List<Clerkinstpos> clerkinstposList) {
		float basicSalaryMoneySum = 0;
		for (Clerkinstpos clerkinstpos : clerkinstposList) {
			// 获得该员工的薪酬标准编号
			String salaryStandardId = this.possalarystandardMapper
					.selectByPrimaryKey(clerkinstpos.getPosid())
					.getSalarystandardid();
			// 根据薪酬标准编号得出该薪酬标准的基本薪酬
			float basicSalary = this
					.getBasicSalaryMoneyBySalarystandardId(salaryStandardId);
			basicSalaryMoneySum += basicSalary;
		}
		return basicSalaryMoneySum;
	}

	@Override
	public List<SalaryDistributionDetailVO> getSalaryDistributionDetailVOListByClerkintpos(
			List<Clerkinstpos> clerkinstpos) {
		List<SalaryDistributionDetailVO> salaryDistributionDetailVOs = new ArrayList<SalaryDistributionDetailVO>();
		for (Clerkinstpos cip : clerkinstpos) {
			/**
			 * 用于封装员工的详细薪酬信息
			 */
			SalaryDistributionDetailVO salaryDistributionDetailVO = new SalaryDistributionDetailVO();

			/**
			 *  获得该员工的薪酬标准编号
			 */
			String salaryStandardId = this.possalarystandardMapper
					.selectByPrimaryKey(cip.getPosid()).getSalarystandardid();

			/**
			 * 根据薪酬标准编号获得该员工的薪酬标准
			 */
			Salarystandard salarystandard = this.findById(salaryStandardId);

			/**
			 * 封装该员工的薪酬标准信息
			 */
			BeanUtils
					.copyProperties(salarystandard, salaryDistributionDetailVO);

			/**
			 *  根据员工编号获得该员工的档案信息
			 */
			Clerkrecords clerkrecords = this.clerkRecordService
					.findByClerkId(cip.getClerkid());

			// 封装档案编号
			salaryDistributionDetailVO
					.setRecordsid(clerkrecords.getRecordsid());

			/**
			 * 根据员工编号获得员工
			 */
			Clerkbaseinfo clerkbaseinfo = this.clerkBaseInfoService
					.findById(cip.getClerkid());
			// 封装员工姓名
			salaryDistributionDetailVO.setClerkname(clerkbaseinfo
					.getClerkname());

			/**
			 * 根据员工编号获得员工的奖惩情况
			 */
			List<Clerkrewardpunishstandard> clerkrewardpunishstandards = this
					.clerkrewardpunishstandardsByClerkId(cip.getClerkid());

			/**
			 * 封装员工应奖金额和应罚金额
			 */
			float reward = 0;// 应奖金额
			float punish = 0;// 应罚金额
			for (Clerkrewardpunishstandard clerkrewardpunishstandard : clerkrewardpunishstandards) {

				/**
				 * 根据奖惩编号获得员工奖惩标准
				 */
				Rewardpunishmentstandard rewardpunishmentstandard = this
						.rewardpunishmentstandard(clerkrewardpunishstandard
								.getRewardpunishmentstandardid());
				if (rewardpunishmentstandard.getRewardpunishmoney() < 0) {
					punish += Math.abs(rewardpunishmentstandard
							.getRewardpunishmoney());
				} else {
					reward += rewardpunishmentstandard.getRewardpunishmoney();
				}
			}
			salaryDistributionDetailVO.setRewardmoney(reward);
			salaryDistributionDetailVO.setPunishmoney(punish);
			salaryDistributionDetailVOs.add(salaryDistributionDetailVO);
		}
		return salaryDistributionDetailVOs;
	}

	@Override
	public List<Clerkrewardpunishstandard> clerkrewardpunishstandardsByClerkId(
			Integer ClerkId) {
		ClerkrewardpunishstandardExample clerkrewardpunishstandardExample = new ClerkrewardpunishstandardExample();
		ClerkrewardpunishstandardExample.Criteria criteria = clerkrewardpunishstandardExample
				.createCriteria();
		criteria.andClerkidEqualTo(ClerkId);
		return this.clerkrewardpunishstandardMapper
				.selectByExample(clerkrewardpunishstandardExample);

	}

	@Override
	public Rewardpunishmentstandard rewardpunishmentstandard(
			String rewardpunishmentstandardId) {
		return this.rewardpunishmentstandardMapper
				.selectByPrimaryKey(rewardpunishmentstandardId);
	}

	@Override
	public void createSalaryDistribution(Salarydistribution salarydistribution) {
		this.salarydistributionMapper.insertSelective(salarydistribution);
	}

	@Override
	public List<Salarydistribution> findSalaryDistributionNoCheck() {
		SalarydistributionExample salarydistributionExample = new SalarydistributionExample();
		SalarydistributionExample.Criteria criteria = salarydistributionExample
				.createCriteria();
		criteria.andIscheckEqualTo(Constant.SALARYNOCHECK);
		return this.salarydistributionMapper
				.selectByExample(salarydistributionExample);
	}

	@Override
	public Salarydistribution findSalarydistributionByInstName(String instname) {
		SalarydistributionExample salarydistributionExample = new SalarydistributionExample();
		SalarydistributionExample.Criteria criteria = salarydistributionExample
				.createCriteria();
		criteria.andInstnameEqualTo(instname);
		List<Salarydistribution> list = this.salarydistributionMapper
				.selectByExample(salarydistributionExample);
		return list.size() > 0 ? list.get(0) : null;
	}

	@Override
	public void createOrupdateSalarydistribution(String instname, String posname) {
		// 获得该职位的薪酬标准编号
		String salarystandardId = this.posService.findByPosId(
				this.posService.findByName(posname).getPosid())
				.getSalarystandardid();
		// 获得该薪酬标准的基本总额
		Float basicSalarySum = this
				.getBasicSalaryMoneyBySalarystandardId(salarystandardId);

		if (this.findSalarydistributionByInstName(instname) == null) {// 当前不存在该机构的薪酬发放单
			// 生成该机构的薪酬发放单
			/**
			 * 生成薪酬发放单编号
			 */
			String salarydistributionId = RandomUtils.generateString(16);
			Salarydistribution salarydistribution = new Salarydistribution();
			// 设置薪酬发放单编号
			salarydistribution.setSalarydistributionid(salarydistributionId);
			// 设置机构名
			salarydistribution.setInstname(instname);
			// 设置为待登记
			salarydistribution.setIsbook(Constant.SALARYNOBOOK);
			// 设置人数为1
			salarydistribution.setPersonnum(1);
			// 设置薪酬基本总额
			salarydistribution.setBasicsalarysum(basicSalarySum);
			// 添加该薪酬发放单
			this.salarydistributionMapper.insertSelective(salarydistribution);
		} else {// 存在该机构组的薪酬发放单
			/**
			 * 根据机构名获得薪酬发放单
			 */
			Salarydistribution salarydistributionsource = this
					.findSalarydistributionByInstName(instname);
			Salarydistribution salarydistribution = new Salarydistribution();
			BeanUtils.copyProperties(salarydistributionsource,
					salarydistribution);
			// 设置为待登记
			salarydistribution.setIsbook(Constant.SALARYNOBOOK);
			// 设置人数加1
			salarydistribution.setPersonnum(salarydistributionsource
					.getPersonnum() + 1);
			// 设置薪酬基本总额
			salarydistribution.setBasicsalarysum(salarydistribution
					.getBasicsalarysum() + basicSalarySum);
			// 更新该薪酬发放单
			this.salarydistributionMapper
					.updateByPrimaryKeySelective(salarydistribution);
		}
	}

	@Override
	public List<Salarydistribution> findAllSalarystandardNoBook() {
		SalarydistributionExample salarydistributionExample = new SalarydistributionExample();
		SalarydistributionExample.Criteria criteria = salarydistributionExample
				.createCriteria();
		criteria.andIsbookEqualTo(Constant.SALARYNOBOOK);
		return this.salarydistributionMapper
				.selectByExample(salarydistributionExample);
	}

	@Override
	public void createSalarydistributiondetail(String recordsid,
			Integer clerkid, String instname, Salarystandard salarystandard) {
		Salarydistributiondetail salarydistributiondetail = new Salarydistributiondetail();
		BeanUtils.copyProperties(salarystandard, salarydistributiondetail);

		/**
		 * 设置档案编号
		 */
		salarydistributiondetail.setRecordsid(recordsid);

		/**
		 *  设置员工编号
		 */
		salarydistributiondetail.setClerkid(clerkid);
		/**
		 * 设置奖励金额和应扣金额为0
		 */
		salarydistributiondetail.setRewardmoney((float) 0);
		salarydistributiondetail.setPunishmoney((float) 0);

		/**
		 * 设置三级机构名
		 */
		salarydistributiondetail.setThirdinstname(instname);

		/**
		 * 设置其状态为待登记
		 */
		salarydistributiondetail.setAuditstate(Constant.SALARYNOBOOK);

		/**
		 * 添加员工薪酬详细发放表
		 */
		this.salarydistributiondetailMapper
				.insertSelective(salarydistributiondetail);
	}

	@Override
	public List<Salarydistributiondetail> findByInstname(String instname,
			String auditstate) {
		SalarydistributiondetailExample salarydistributiondetailExample = new SalarydistributiondetailExample();
		SalarydistributiondetailExample.Criteria criteria = salarydistributiondetailExample
				.createCriteria();
		criteria.andThirdinstnameEqualTo(instname);
		criteria.andAuditstateEqualTo(auditstate);
		return this.salarydistributiondetailMapper
				.selectByExample(salarydistributiondetailExample);
	}

	@Override
	public void updateSalaryDistributionDetail(
			Salarydistributiondetail salaryDistributionDetail) {
		this.salarydistributiondetailMapper
				.updateByPrimaryKeySelective(salaryDistributionDetail);
		/**
		 * 查询是该机构下是否还有待登记的薪酬详情
		 */
		if (salaryDistributionDetail.getAuditstate().equals(
				Constant.SALARYNOCHECK)) {
			SalarydistributiondetailExample salarydistributiondetailExample = new SalarydistributiondetailExample();
			SalarydistributiondetailExample.Criteria criteria = salarydistributiondetailExample
					.createCriteria();
			criteria.andAuditstateEqualTo(Constant.SALARYNOBOOK);
			criteria.andThirdinstnameEqualTo(salaryDistributionDetail
					.getThirdinstname());
			List<Salarydistributiondetail> salarydistributiondetails = this.salarydistributiondetailMapper
					.selectByExample(salarydistributiondetailExample);
			/**
			 * 如果该机构下的员工都登记完了，设置为登记，并且设置为待复核
			 */
			Salarydistribution salarydistribution = this
					.findSalarydistributionByInstName(salaryDistributionDetail
							.getThirdinstname());
			if (salarydistributiondetails.size() == 0) {
				/**
				 * 设置该机构的薪酬发放为登记
				 */
				// 设置为登记
				salarydistribution.setIsbook(Constant.BOOK);
				// 设置为待复核
				salarydistribution.setIscheck(Constant.SALARYNOCHECK);
				this.salarydistributionMapper
						.updateByPrimaryKeySelective(salarydistribution);
			} else {// 否则设置为待复核
				salarydistribution.setIscheck(Constant.SALARYNOCHECK);
				this.salarydistributionMapper
						.updateByPrimaryKeySelective(salarydistribution);
			}

		}
		/**
		 * 如果传过来是执行的话
		 */
		if (salaryDistributionDetail.getAuditstate().equals(
				Constant.SALARYCHECKED)) {
			SalarydistributiondetailExample salarydistributiondetailExample = new SalarydistributiondetailExample();
			SalarydistributiondetailExample.Criteria criteria = salarydistributiondetailExample
					.createCriteria();
			criteria.andAuditstateEqualTo(Constant.SALARYNOCHECK);
			criteria.andThirdinstnameEqualTo(salaryDistributionDetail
					.getThirdinstname());
			List<Salarydistributiondetail> salarydistributiondetails = this.salarydistributiondetailMapper
					.selectByExample(salarydistributiondetailExample);
			/**
			 * 如果该机构下的员工都复核完了，设置为登记，并且设置为执行
			 */
			Salarydistribution salarydistribution = this
					.findSalarydistributionByInstName(salaryDistributionDetail
							.getThirdinstname());
			if (salarydistributiondetails.size() == 0) {
				/**
				 * 设置该机构的薪酬发放为登记
				 */

				// 设置为登记
				salarydistribution.setIsbook(Constant.BOOK);
				// 设置为执行
				salarydistribution.setIscheck(Constant.SALARYCHECKED);
				this.salarydistributionMapper
						.updateByPrimaryKeySelective(salarydistribution);
			} else {
				// 设置为待复核
				salarydistribution.setIscheck(Constant.CLERKNOCHECK);
				this.salarydistributionMapper
						.updateByPrimaryKeySelective(salarydistribution);
			}
		}

	}

	@Override
	public void updateSalaryDistribution(
			Salarydistributiondetail salaryDistributionDetail) {
		/**
		 * 根据三级机构名获取薪酬发放表
		 */
		Salarydistribution salarydistribution = this
				.findSalarydistributionByInstName(salaryDistributionDetail
						.getThirdinstname());

		// /**
		// * 设置状态
		// */
		// salarydistribution.setIscheck(salaryDistributionDetail.getAuditstate());
		// if (salaryDistributionDetail.equals(Constant.SALARYNOCHECK)) {
		// /**
		// * 设置为登记
		// */
		// salarydistribution.setIsbook(Constant.BOOK);
		// }

		/**
		 * 设置薪酬发放基本总额
		 * * 1、获得修改前的基本薪酬总额sum
		 * * 2、获得当前该员工薪酬的基本总额sumclerk
		 * * 3、sum - sumclerk
		 * * 4、加上修改后的该员工的基本薪酬总额
		 */
		Salarydistributiondetail salarydistributiondetailoriginal = this.salarydistributiondetailMapper
				.selectByPrimaryKey(salaryDistributionDetail.getClerkid());

		Float originalsum = this
				.CaculateSalaryDistributionDetail(salarydistributiondetailoriginal);
		Float nowsum = this
				.CaculateSalaryDistributionDetail(salaryDistributionDetail);
		salarydistribution.setBasicsalarysum(salarydistribution
				.getBasicsalarysum() - originalsum + nowsum);
		this.salarydistributionMapper
				.updateByPrimaryKeySelective(salarydistribution);
	}

	@Override
	public Float CaculateSalaryDistributionDetail(
			Salarydistributiondetail salarydistributiondetail) {
		float salarysum = 0;
		if (salarydistributiondetail.getBasicsalary() != null) {
			salarysum += salarydistributiondetail.getBasicsalary();
		}
		if (salarydistributiondetail.getTrafficallowance() != null) {
			salarysum += salarydistributiondetail.getTrafficallowance();
		}
		if (salarydistributiondetail.getLunchallowance() != null) {
			salarysum += salarydistributiondetail.getLunchallowance();
		}
		if (salarydistributiondetail.getCommallowance() != null) {
			salarysum += salarydistributiondetail.getCommallowance();
		}
		if (salarydistributiondetail.getEndowmentins() != null) {
			salarysum -= salarydistributiondetail.getEndowmentins();
		}
		if (salarydistributiondetail.getMedicalins() != null) {
			salarysum -= salarydistributiondetail.getMedicalins();
		}
		if (salarydistributiondetail.getUneloymentins() != null) {
			salarysum -= salarydistributiondetail.getUneloymentins();
		}
		if (salarydistributiondetail.getHousingfund() != null) {
			salarysum -= salarydistributiondetail.getHousingfund();
		}
		return salarysum;
	}

	@Override
	public List<Salarydistribution> findAllSalarystandardNoCheck() {
		SalarydistributionExample salarydistributionExample = new SalarydistributionExample();
		SalarydistributionExample.Criteria criteria = salarydistributionExample
				.createCriteria();
		criteria.andIsbookEqualTo(Constant.SALARYNOCHECK);
		return this.salarydistributionMapper
				.selectByExample(salarydistributionExample);
	}
}
